package com.shoeshopping.action.pc;

import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.shoeshopping.entity.DeliveryAddress;
import com.shoeshopping.entity.GoodsItem;
import com.shoeshopping.entity.OrderItem;
import com.shoeshopping.service.pc.GetIntoCartService;
import com.shoeshopping.service.pc.GetIntoOrderService;
import com.shoeshopping.utils.pc.Result;

@Controller("orderItemAction")
public class OrderItemAction extends ActionSupport {

	OrderItem orderItem;
	
	DeliveryAddress deliveryAddress;
	
	String otherAdd;

	@Resource(name="getIntoOrderService")
	GetIntoOrderService getIntoOrderService;
	
	@Resource(name="getIntoCartService")
	GetIntoCartService getIntoCartService;
	

	public String getOtherAdd() {
		return otherAdd;
	}

	public void setOtherAdd(String otherAdd) {
		this.otherAdd = otherAdd;
	}

	public OrderItem getOrderItem() {
		return orderItem;
	}

	public void setOrderItem(OrderItem orderItem) {
		this.orderItem = orderItem;
	}

	public GetIntoOrderService getGetIntoOrderService() {
		return getIntoOrderService;
	}

	public void setGetIntoOrderService(GetIntoOrderService getIntoOrderService) {
		this.getIntoOrderService = getIntoOrderService;
	}
	
	public DeliveryAddress getDeliveryAddress() {
		return deliveryAddress;
	}

	public void setDeliveryAddress(DeliveryAddress deliveryAddress) {
		this.deliveryAddress = deliveryAddress;
	}

	public String save() {
		
		List orderItemList = getIntoOrderService.save(orderItem,deliveryAddress,otherAdd);

		for(Iterator it = orderItemList.iterator();it.hasNext();) {
			GoodsItem goodsItem = (GoodsItem) it.next();
			getIntoCartService.delete(goodsItem);
		}
		
		return Result.SUCCESS;
	}

	public String show() {
		
		getIntoOrderService.show();
		
		return Result.SUCCESS;
	}

}
